using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using TomShane.Neoforce.Controls;

namespace Madrigal
{
    public enum ConnectionSteps
    {
        LoginStart,
        CheckUP,
        ErrorLog,
        ServerListEntry,
        ErrorServer,
        CharList,
        ErrorChar,
        WorldEntry,
        ErrorWorld,
    }

    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class OpenNeuz : Game
    {
        private GraphicsDeviceManager graphicsManager;
        Manager NeoForceManager;
        ScreenManager screenManager;
        private SpriteBatch sprite;

        ConnectionSteps conStep = ConnectionSteps.WorldEntry;

        public OpenNeuz()
        {
            graphicsManager = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            IsMouseVisible = true;
            IsFixedTimeStep = false;
            graphicsManager.PreferredBackBufferWidth = 1024;
            graphicsManager.PreferredBackBufferHeight = 768;
            graphicsManager.SynchronizeWithVerticalRetrace = false;

            NeoForceManager = new Manager(this, graphicsManager, "Default");
            screenManager = new ScreenManager(this);
            NeoForceManager.SkinDirectory = @"Content\Textures\Skins\";
            Components.Add(screenManager);
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {

            base.Initialize();

            // Create sprite batch for ploting texture with rendered UI.
            sprite = new SpriteBatch(GraphicsDevice);

            // Initialize manager.
            NeoForceManager.Initialize();
            // Create and assign render target for UI rendering.
            NeoForceManager.RenderTarget = new RenderTarget2D(GraphicsDevice, graphicsManager.PreferredBackBufferWidth, graphicsManager.PreferredBackBufferHeight, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.DiscardContents);
            NeoForceManager.TargetFrames = 60;

            screenManager.AddScreen(new BackgroundScreen(@"Textures\UI\screen1"), null);
            //screenManager.AddScreen(new LoginScreen(screenManager, NeoForceManager), null);
            screenManager.AddScreen(new WndDialog(screenManager, NeoForceManager, 1, "Hello, this is a test!!!"), null);
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            base.Update(gameTime);

            // Call manager updates.
            NeoForceManager.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            // We need to draw controls before first draw to back buffer to avoid back buffer purple clear.
            NeoForceManager.BeginDraw(gameTime);

            GraphicsDevice.Clear(Color.CornflowerBlue);

            base.Draw(gameTime);

            NeoForceManager.EndDraw();
        }
    }
}
